//
//  RegisterViewController.m
//  WeChat
//
//  Created by wangcarl on 16/8/30.
//  Copyright © 2016年 wangcarl. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController ()
- (IBAction)cancelBTNClick:(id)sender;
- (IBAction)registerBTNClick:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UITextField *userTextField;
@property (weak, nonatomic) IBOutlet UITextField *pwdTextField;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)cancelBTNClick:(id)sender {
}

- (IBAction)registerBTNClick:(UIButton *)sender {
    
    [Account shareAccount].registerUser=self.userTextField.text;
    [Account shareAccount].registerPwd=self.pwdTextField.text;
    
    [MBProgressHUD showMessage:@"正在注册中。。。"];
    
    [XMPPTool sharedXMPPTool].registerOperation=YES;
    
    __weak typeof(self) selfVc=self;
    [[XMPPTool sharedXMPPTool] xmppRegister:^(XMPPResultType resultType) {
        [selfVc handleXMPPResult:resultType];
    }];
   

}

-(void)handleXMPPResult:(XMPPResultType) resultType
{
dispatch_async(dispatch_get_main_queue(), ^{
    [MBProgressHUD hideHUD];
    if (resultType==XMPPResultTypeRegisterSucess) {
        [MBProgressHUD showSuccess:@"恭喜注册成功"];
    }else
    {
        [MBProgressHUD showError:@"用户名重复"];
    }
});
}
@end
